#include "StdAfx.h"
#include "vstyle.h"
#include "vcontrol.h"

VStyle::VStyle(QObject* parent)
: QObject(parent)
, m_bgColor("white")
{
	m_font.setFamily("Times New Roman");
	m_font.setPointSize(12);
}

QString VStyle::family() const
{
	return m_font.family();
}

void VStyle::setFamily(const QString& family)
{
	m_font.setFamily(family);
}

int VStyle::pointSize() const
{
	return m_font.pointSize();
}

void VStyle::setPointSize(int pointSize)
{
	m_font.setPointSize(pointSize);
}

bool VStyle::bold() const
{
	return m_font.bold();
}

void VStyle::setBold(bool enable)
{
	m_font.setBold(enable);
}

bool VStyle::italic() const
{
	return m_font.italic();
}

void VStyle::setItalic(bool enable)
{
	m_font.setItalic(enable);
}

bool VStyle::underline() const
{
	return m_font.underline();
}

void VStyle::setUnderline(bool enable)
{
	m_font.setUnderline(enable);
}

QColor VStyle::color() const
{
	return m_color;
}

void VStyle::setColor(const QColor& color)
{
	m_color = color;
}

QColor VStyle::bgColor() const
{
	return m_bgColor;
}

void VStyle::setBgColor(const QColor& bgColor)
{
	m_bgColor = bgColor;
}

void VStyle::show()
{
	QList<QByteArray> propList(QObject::dynamicPropertyNames());
	QString str;
	foreach(str, propList)
		qDebug() << str;
}

QFont VStyle::font() const
{
	return m_font;
}

void VStyle::setFont(const QFont& font)
{
	m_font = font;
}

QString VStyle::serialize() const
{
	QString tmpl("VStyle { id: %name%; name: %name%; family: %family%; pointSize: %pointSize%; bold: %bold%; underline: %underline%; italic: %italic%; color: %color%; bgColor: %bgColor%; }");
	
	QString script;

	script.append(VCTRL_STYLE + " { ");
	script.append("id: " + m_name + "; ");
	script.append("name: \"" + QObject::objectName() + "\"; ");

	//font
	script.append("family: \"" + m_font.family() + "\"; ");
	script.append("pointSize: " + QString("%1").arg(m_font.pointSize()) + "; ");
	QString s(m_font.bold()?"true":"false");
	script.append("bold: " + s + "; ");
	s = m_font.italic()?"true":"false";
	script.append("italic: " + s + "; ");
	s = m_font.underline()?"true":"false";
	script.append("underline: " + s + "; ");
	
	//colors
	QString red;
	QString green;
	QString blue;

	m_color.red()?
		red = QString("%1").arg(m_color.red(), 0, 16):
		red = QString("0%1").arg(m_color.red(), 0, 16);

	m_color.green()?
		green = QString("%1").arg(m_color.green(), 0, 16):
		green = QString("0%1").arg(m_color.green(), 0, 16);

	m_color.blue()?
		blue = QString("%1").arg(m_color.blue(), 0, 16):
		blue = QString("0%1").arg(m_color.blue(), 0, 16);
		
	script.append("color: \"" + QString("#%1%2%3").arg(red).arg(green).arg(blue) + "\"; ");

	m_bgColor.red()?
		red = QString("%1").arg(m_bgColor.red(), 0, 16):
		red = QString("0%1").arg(m_bgColor.red(), 0, 16);

	m_bgColor.green()?
		green = QString("%1").arg(m_bgColor.green(), 0, 16):
		green = QString("0%1").arg(m_bgColor.green(), 0, 16);

	m_bgColor.blue()?
		blue = QString("%1").arg(m_bgColor.blue(), 0, 16):
		blue = QString("0%1").arg(m_bgColor.blue(), 0, 16);

	script.append("bgColor: \"" + QString("#%1%2%3").arg(red).arg(green).arg(blue) + "\"; ");
	
	script.append(" }");
	
	return script;
}
